package com.suemi.rpc.entity;

import java.util.HashMap;
import java.util.Map;

public class RpcHeader {

  private long crcCode;

  private int length;

  private long sender;

  private byte type;

  private byte version;

  private Map<String, String> attachments = new HashMap<>();

  public long getCrcCode() {
    return crcCode;
  }

  public void setCrcCode(long crcCode) {
    this.crcCode = crcCode;
  }

  public int getLength() {
    return length;
  }

  public void setLength(int length) {
    this.length = length;
  }

  public long getSender() {
    return sender;
  }

  public void setSender(long sender) {
    this.sender = sender;
  }

  public MessageType getType() {
    return MessageType.from(type);
  }

  public void setType(MessageType type) {
    this.type = type.value();
  }

  public byte getVersion() {
    return version;
  }

  public void setVersion(byte version) {
    this.version = version;
  }

  public Map<String, String> getAttachments() {
    if (attachments == null) attachments = new HashMap<>();
    return attachments;
  }

  public void setAttachments(Map<String, String> attachments) {
    this.attachments = attachments;
  }

  @Override
  public String toString() {
    return "RpcHeader{" +
            "crcCode=" + crcCode +
            ", length=" + length +
            ", sender=" + sender +
            ", type=" + type +
            ", version=" + version +
            ", attachments=" + attachments +
            '}';
  }


}
